import request, { Config } from "@/utils/request";

// 上传文件
export async function uploadFileApi(params: any) {
  return request("/file/upload", {
    method: "POST",
    data: params,
    serviceId: "fwFile",
  });
}

// 登录
export async function accountLogin(params: any) {
  return request("/authentication/login", {
    method: "POST",
    data: params,
    serviceId: "fwSecurity",
  });
}

//获取验证码
export function getValidateCodeApi(params = {}) {
  return request("/authentication/getValidateCode", {
    method: "POST",
    data: params,
    serviceId: "fwSecurity",
  });
}

// 验证码登录 {"userLoginName":"","password":"","usertype":null,"validateCodeId":"","validateCode":""}
export async function accountLoginWithValidateCode(params: any) {
  return request("/authentication/login2", {
    method: "POST",
    data: params,
    serviceId: "fwSecurity",
  });
}

// 根据Cookie内容，设置本地属性
export async function checkToken(params: any) {
  return request("/authentication/checkToken", {
    method: "POST",
    data: params,
    serviceId: "fwSecurity",
  });
}
// 验证ssoToken并转换为甘棠Token, 写入到Cookie中
export async function ssoLogin(params: any) {
  const { ssoTokenType, ssoToken } = params;
  return request(
    `/authentication/ssoLogin?tokenType=${ssoTokenType}&token=${ssoToken}`,
    {
      method: "POST",
      serviceId: "fwSecurity",
    }
  );
}
//在检测cookie中是否包含userIdentity信息, 如果有，则跳过登录界面直接进入创建桌面阶段
export async function getProductName(params: any) {
  return request("/platformManage/getProductName", {
    method: "POST",
  });
}

// 获取代理信息
export async function getDelegateInfo(params: any) {
  return request("/delegateAuth/getDelegateInfo", {
    method: "POST",
    data: params,
    serviceId: "fwSecurity",
  });
}

// 进入代理
export async function delegateLogin(params: any) {
  return request("/delegateAuth/delegateLogin", {
    method: "POST",
    data: params,
    serviceId: "fwSecurity",
  });
}

// 退出代理
export async function delegateLogout(params: any) {
  return request("/delegateAuth/delegateLogout", {
    method: "POST",
    data: params,
    serviceId: "fwSecurity",
  });
}

// 获取主菜单
export const getStartMenuAPI = () =>
  request("/security/getStartMenu", {
    params: { _dc: Date.now() },
    serviceId: "fwSecurity",
  });
export const getReactStartMenuAPI = () =>
  request("/security/getStartMenu", {
    params: { _dc: Date.now() },
    serviceId: "fwSecurity",
  });

// 上下文菜单
export const getContextMenuAPI = (payload: any) =>
  request("/security/getContextMenu", {
    params: {
      contextCategory: payload,
      _dc: Date.now(),
    },
    serviceId: "fwSecurity",
  });

// 获取概要信息
export const getBizSummary = request.post.bind(
  null,
  "/bizSummary/getBizSummary"
);

//公司定制化数据接口
export async function setUserData(params: any, config?: Config) {
  return request(
    "/accountUserSelf/setUserData",
    {
      method: "POST",
      data: params,
      serviceId: "fwSecurity",
    },
    config
  );
}

//获取公司定制化信息
export async function getUserData(params: any) {
  return request("/accountUserSelf/getUserData", {
    method: "POST",
    data: params,
    serviceId: "fwSecurity",
  });
}

//删除公司定制化信息
export async function delUserData(params: any) {
  return request("/accountUserSelf/delUserData", {
    method: "POST",
    data: params,
    serviceId: "fwSecurity",
  });
}

//公司定制化数据接口
export async function setCompanyData(params: any) {
  return request("/companyData/setCompanyData", {
    method: "POST",
    data: params,
    serviceId: "fwSecurity",
  });
}

//获取公司定制化信息
export async function getCompanyData(params: any) {
  return request("/companyData/getCompanyData", {
    method: "POST",
    data: params,
    serviceId: "fwSecurity",
  });
}

//删除公司定制化信息
export async function delCompanyData(params: any) {
  return request(
    "/companyData/delCompanyData",
    {
      method: "POST",
      data: params,
      serviceId: "fwSecurity",
    },
    {
      showSuccess: true,
      successMessage: "删除成功" + "，" + "在下次刷新时生效",
    }
  );
}

//获取当前用户仪表板信息
export async function fetchDashboards() {
  return request("/accountUserSelf/getUserData", {
    method: "POST",
    data: {
      dataId: "mgmt",
      dataType: "dashboard",
    },
    serviceId: "fwSecurity",
  });
}

//获取系统参数
export async function fetchSystemParameters() {
  return request("/parameter/findAll", {
    method: "POST",
    data: {},
    headers: {
      needHtmlEscape: "false",
    },
    serviceId: "fwPlatform",
  });
}

export async function parameterValueByNameApi(params: { value: string }) {
  return request("/parameter/getByName", {
    method: "POST",
    data: params,
    headers: {
      needHtmlEscape: "false",
    },
    serviceId: "fwPlatform",
  });
}

//获取系统参数
export async function findAllCodeList() {
  return request("/codeList/findAll", {
    method: "POST",
    data: {},
    serviceId: "fwPlatform",
  });
}

//上报用户操作数据
export async function reportTrackApi(params: any) {
  return request("/security/recordUserActionLog", {
    method: "POST",
    data: {
      logs: params,
    },
    serviceId: "fwPlatform",
  });
}

//取得平台聚合信息
export async function getPlatformAggregateInfoApi(params: any) {
  return request("/platformManage/getPlatformAggregateInfo", {
    method: "POST",
    data: params,
  });
}

//取得用户帐号信息设置聚合策略
export async function getAccountAggregateStrategyApi() {
  return request("/security/getAccountAggregateStrategy", {
    method: "POST"
  });
}



